package com.hckjsec.cloud.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.hckjsec.cloud.domain.AppletsConfigParamDetail;
import com.hckjsec.cloud.domain.view.*;
import com.hckjsec.cloud.enums.BasicParamEnum;
import com.hckjsec.cloud.mapper.AppletsConfigParamDetailMapper;
import com.hckjsec.cloud.service.IAppletsConfigParamDetailService;
import com.hckjsec.common.init.YwInitData;
import com.hckjsec.common.utils.ComUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 配置参数明细Service业务层处理
 * 
 * @author cyt
 * @date 2021-07-29
 */
@Service
public class AppletsConfigParamDetailServiceImpl implements IAppletsConfigParamDetailService
{
    @Autowired
    private AppletsConfigParamDetailMapper appletsConfigParamDetailMapper;

    @Autowired
    private YwInitData ywInitData;
    /**
     * 查询配置参数明细
     * 
     * @param id 配置参数明细ID
     * @return 配置参数明细
     */
    @Override
    public AppletsConfigParamDetail selectAppletsConfigParamDetailById(Long id)
    {
        return appletsConfigParamDetailMapper.selectAppletsConfigParamDetailById(id);
    }

    /**
     * 查询配置参数明细列表
     * 
     * @param appletsConfigParamDetail 配置参数明细
     * @return 配置参数明细
     */
    @Override
    public List<AppletsConfigParamDetail> selectAppletsConfigParamDetailList(AppletsConfigParamDetail appletsConfigParamDetail)
    {
        return appletsConfigParamDetailMapper.selectAppletsConfigParamDetailList(appletsConfigParamDetail);
    }

    /**
     * 新增配置参数明细
     * 
     * @param appletsConfigParamDetail 配置参数明细
     * @return 结果
     */
    @Override
    public int insertAppletsConfigParamDetail(AppletsConfigParamDetail appletsConfigParamDetail)
    {
        return appletsConfigParamDetailMapper.insertAppletsConfigParamDetail(appletsConfigParamDetail);
    }

    /**
     * 修改配置参数明细
     * 
     * @param appletsConfigParamDetail 配置参数明细
     * @return 结果
     */
    @Override
    public int updateAppletsConfigParamDetail(AppletsConfigParamDetail appletsConfigParamDetail)
    {
        return appletsConfigParamDetailMapper.updateAppletsConfigParamDetail(appletsConfigParamDetail);
    }

    /**
     * 批量删除配置参数明细
     * 
     * @param ids 需要删除的配置参数明细ID
     * @return 结果
     */
    @Override
    public int deleteAppletsConfigParamDetailByIds(Long[] ids)
    {
        return appletsConfigParamDetailMapper.deleteAppletsConfigParamDetailByIds(ids);
    }

    /**
     * 删除配置参数明细信息
     * 
     * @param id 配置参数明细ID
     * @return 结果
     */
    @Override
    public int deleteAppletsConfigParamDetailById(Long id)
    {
        return appletsConfigParamDetailMapper.deleteAppletsConfigParamDetailById(id);
    }

    @Override
    public int deleteAppletsConfigParamDetailByConfigId(AppletsConfigParamDetail appletsConfigParamDetail) {
        return appletsConfigParamDetailMapper.deleteAppletsConfigParamDetailByConfigId(appletsConfigParamDetail);
    }

    @Override
    public BasicView getBasicView(Long id){
        BasicView basicView = new BasicView();
        KvView inform = new KvView("");
        BdocrView bdocr = new BdocrView("","","");
        List<KvView> rotationList = new ArrayList<KvView>();
        TemplateView template = new TemplateView("","","");
        RemotevideoView remotevideo = new RemotevideoView("","","","");
        MessageView message = new MessageView("","","","");
        MenuView menu =  new MenuView("","","","","","","","");
        CheckView livingthing = new CheckView("","","","");
        CheckView identity = new CheckView("","","","");
        QysView qys = new QysView("","","","","","");
        KvView paycode = new KvView("");
        List<KvView> guideList = new  ArrayList<KvView>();
        AppletsConfigParamDetail appletsConfigParamDetail=new AppletsConfigParamDetail();
        appletsConfigParamDetail.setConfigId(id);
        List<AppletsConfigParamDetail> list = appletsConfigParamDetailMapper.selectAppletsConfigParamDetailList(appletsConfigParamDetail);
        list.forEach(dv -> {
            if (BasicParamEnum.SYS_APPLETS_BASIC_INFORM.getKey().equals(dv.getParamnumber())){
                inform.setValue(dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_BDOCR.getKey().equals(dv.getParamnumber())){
                ComUtil.setFields(bdocr,dv.getParamdetailnumber(),dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_ROTATION.getKey().equals(dv.getParamnumber())){
                KvView rotation = new KvView("","");
                rotation.setName(dv.getName());
                rotation.setUrl(dv.getContent());
                rotationList.add(rotation);
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_TEMPLATE.getKey().equals(dv.getParamnumber())){
                ComUtil.setFields(template,dv.getParamdetailnumber(),dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_REMOTEVIDEO.getKey().equals(dv.getParamnumber())){
                ComUtil.setFields(remotevideo,dv.getParamdetailnumber(),dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_MESSAGE.getKey().equals(dv.getParamnumber())){
                ComUtil.setFields(message,dv.getParamdetailnumber(),dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_MENU.getKey().equals(dv.getParamnumber())){
                ComUtil.setFields(menu,dv.getParamdetailnumber(),dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_LIVINGTHING.getKey().equals(dv.getParamnumber())) {
                ComUtil.setFields(livingthing, dv.getParamdetailnumber(), dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_IDENTITY.getKey().equals(dv.getParamnumber())) {
                ComUtil.setFields(identity, dv.getParamdetailnumber(), dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_QYS.getKey().equals(dv.getParamnumber())) {
                ComUtil.setFields(qys, dv.getParamdetailnumber(), dv.getContent());
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_GUIDE.getKey().equals(dv.getParamnumber())){
                KvView guide = new KvView("","");
                guide.setName(dv.getName());
                guide.setUrl(dv.getContent());
                guideList.add(guide);
            }else if(BasicParamEnum.SYS_APPLETS_BASIC_PAYMENT.getKey().equals(dv.getParamnumber())){
                paycode.setUrl(dv.getContent());
                paycode.setName(dv.getName());
            }
        });
        basicView.setInform(inform);
        basicView.setBdocr(bdocr);
        basicView.setRotation(rotationList);
        basicView.setTemplate(template);
        basicView.setRemotevideo(remotevideo);
        basicView.setMessage(message);
        basicView.setMenu(menu);
        basicView.setLivingthing(livingthing);
        basicView.setIdentity(identity);
        basicView.setQys(qys);
        basicView.setGuide(guideList);
        basicView.setPayment(paycode);
        return basicView;
    }
    /**
     * 小程序初始化参数参数
     *
     * @param id applets配置ID
     * @return 结果
     */
    @Override
    public  void IdByBasicViewInit(Long id,BasicView basicView){
        ywInitData.modIdByBasicView(id,basicView);
    }
}
